#pragma once

#include <iostream>
#include <stdarg.h>
#include <string>
#include <cstring>
#include <ctime>
#include <unistd.h>

#define DEBUG 0
#define NORMAL 1 // 表示正常
#define WARNING 2
#define ERROR 3 // 表示它出错了，但是还可以继续运行
#define FATAL 4 // 表示致命的 表示一旦出错了，后面就无法继续运行了

const char *to_levelstr(int level)
{
    switch (level)
    {
    case DEBUG:
        return "DEBUG";
    case NORMAL:
        return "NORMAL";
    case WARNING:
        return "WARNING";
    case ERROR:
        return "ERROR";
    case FATAL:
        return "FATAL";
    default:
        return nullptr;
    }
}
// void logMessage(DEBUG,"hello %f %d %c",3.14,10,'C);

void logMessage(int level, const char *format, ...)
{
#define NUM 1024
    char logprefix[NUM];
    snprintf(logprefix, sizeof(logprefix), "[%s][%ld][pid: %d]",
             to_levelstr(level), (long int)time(nullptr), getpid());

    char loglcontent[NUM];
    va_list arg;
    va_start(arg, format);

    vsnprintf(loglcontent, sizeof(loglcontent), format, arg);
    std::cout << logprefix << loglcontent << std::endl;
}